//Name:
//Purpose:
//Author: wjy
//Date: 2022-01-11 19:46:26
//From:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int hour, minute;
    int StartTime[] = {480, 583, 679, 767, 840, 945, 1140, 1305};
    int pos;
    printf("Enter a 24-hour time: ");
    scanf("%d:%d", &hour, &minute);
    for (int i = 0; i < 8; i++)
    {
        if ((hour * 60 + minute) < StartTime[i])
        {
            pos = i;
            break;
        }
    }
    if ((hour * 60 + minute) - StartTime[pos - 1] < StartTime[pos] - (hour * 60 + minute))
    {
        pos--;
    }
    switch (pos)
    {
    case 0:
        printf("Closest departure time is 8:00 a.m., arriving at 10:16 a.m.\n");
        break;
    case 1:
        printf("Closest departure time is 9:43 a.m., arriving at 11:52 a.m.\n");
        break;
    case 2:
        printf("Closest departure time is 11:19 a.m., arriving at 1:31 p.m.\n");
        break;
    case 3:
        printf("Closest departure time is 12:47 p.m., arriving at 3:00 p.m.\n");
        break;
    case 4:
        printf("Closest departure time is 2:00 p.m., arriving at 4:08 p.m.\n");
        break;
    case 5:
        printf("Closest departure time is 3:45 p.m., arriving at 5:55 p.m.\n");
        break;
    case 6:
        printf("Closest departure time is 7:00 p.m., arriving at 9:20 p.m.\n");
        break;
    case 7:
        printf("Closest departure time is 9:45 p.m., arriving at 11:58 p.m.\n");
    default:
        break;
    }
    system("pause");
    return 0;
}
